package com.evolved.automata.android.bots.speechbot;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;

public class DataRow extends TableRow 
{
	

	EditText newKey;
	AutoCompleteTextView newValue;
	Button deleteButton;
	DataRow thisDataRow;
	boolean exportedValueP;
	Button expandButton;
	
	InferenceApp outerContex;
	DataInputPanel parentPanel;
	
	public DataRow(Context context, DataInputPanel parent, String keyHint, String valueHint, String keyName, String keyValue) 
	{
		super(context);
		outerContex=(InferenceApp)context;
		parentPanel= parent;
		String infServiceName = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater inflater;
		inflater = (LayoutInflater)context.getSystemService(infServiceName);
		inflater.inflate(R.layout.data_panel_row, this,true);
		thisDataRow = this;
		newKey = (EditText)findViewById(R.id.keyName);
		newKey.setText(keyName);
		newKey.setHint(keyHint);
		newValue = (AutoCompleteTextView)findViewById(R.id.keyValue);
		newValue.setText(keyValue);
		newValue.setHint(valueHint);
		deleteButton = (Button)findViewById(R.id.removeButton);
		expandButton = (Button)findViewById(R.id.dataPropertiesId);
		expandButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) 
			{
				outerContex.showExpandedDialog(newKey, newValue,true);
				
			}
		});
		
		expandButton.setLongClickable(true);
		expandButton.setOnLongClickListener(new View.OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) 
			{
				if (newValue.getText().toString().equals("Question1"))
				{
					newValue.setText("Question2");
					return true;
				}
				else
				{
					if (newValue.getText().toString().equals("Question2"))
					{
						newValue.setText("Question1");
						return true;
					}
				}
				return false;
			}
		});
		
		newKey.setEms(10);
		newValue.setEms(10);
		newKey.setMaxLines(1);
		newValue.setMaxLines(1);
	}
	


	
	public String getValueText()
	{
		return newValue.getText().toString();
	}
	
	public String getNameText()
	{
		return newKey.getText().toString();
	}
	
//	public void setClickAction(View.OnClickListener onClickListener)
//	{
//		deleteButton.setOnClickListener(onClickListener);
//	}
	
	
//	public void setOnLongClickAction(View.OnLongClickListener onLongClickListener)
//	{
//		deleteButton.setOnLongClickListener(onLongClickListener);
//	}
	
	public View getButton()
	{
		return deleteButton;
	}
}


